<template>
  <!--  欠货明细页面  -->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search :config="searchConfig" @search="search" @getHeight="getHeight" />

    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
        :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <!-- 操作按钮区域 -->
          <div class="table-operator">
            <a-button v-has="'ordermgt:export'" @click="downExportXls('owegoods_detail' )">导出</a-button>
          </div>
        </template>
        <template #dataTypeDes="{ row,rowIndex }">
          {{ filterDictText(statusList, row.dataTypeDes) }}
        </template>
        <template #action='{ row }'>
          <a v-has="'business:log'" @click='handleBusiness("欠货明细",row)'>日志</a>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <business-log ref='businessLog'></business-log>
  </a-card>
</template>

<script>
import { PageListMixin } from '@/mixins/PageListMixin'
import { getAction, postAction } from '@api/manage'
import Vue from 'vue'
import { initDictOptions, filterDictText } from '@comp/dict/CnDictSelectUtil'

export default {
  name: 'shortageDetails',
  mixins: [PageListMixin],
  components: {
  },
  data() {
    return {
      selectedRowKeys: [],
      description: '用户组织关系',
      searchConfig: [
        {
          type: 'input',
          name: 'orderCode',
          placeholder: ' DMS订单编号'
        },
        {
          type: 'input',
          name: 'customerCode',
          placeholder: ' 客户编号'
        },
        {
          type: 'input',
          name: 'customerName',
          placeholder: ' 客户名称'
        },
        {
          type: 'input',
          name: 'promotionCode',
          placeholder: ' 政策编号'
        },
        {
          type: 'date-range',
          format: 'YYYY-MM-DD',
          range: ['orderStartDate', 'orderEndDate'],
          name: 'abc',
          placeholder: ['开始时间', '结束时间']
        },
      ],
      //表头
      columns: [],
      //列设置
      statusList:[],
      settingColumns: [],
      defColumns: [
        { type: 'checkbox', width: 60, fixed: 'left' },
        {
          title: '订单编号',
          align: 'left',
          field: 'orderCode',
          minWidth: 100,
        },
        {
          title: '政策编号',
          align: 'left',
          field: 'promotionCode',
          minWidth: 100,
        },
        {
          title: '政策名称',
          align: 'left',
          field: 'promotionName',
          minWidth: 100,
        },
        {
          title: '客户编号',
          align: 'left',
          field: 'customerCode',
          minWidth: 100,
        },
        {
          title: '客户名称',
          align: 'left',
          field: 'customerName',
          minWidth: 100,
        }
        ,{
          title: '赠品类型',
          align: 'left',
          field: 'dataTypeDes',
          minWidth: 80,
          slots: {
            default: 'dataTypeDes'
          }
        },
        ,{
          title: '商品编号',
          align: 'left',
          field: 'productCode',
          minWidth: 100,
        },
        ,{
          title: '商品名称',
          align: 'left',
          field: 'goodsName',
          minWidth: 120,
        },
        ,{
          title: '赠品下单数量',
          align: 'left',
          field: 'quantity',
          minWidth: 80,
        },
        ,{
          title: '赠品发货数量',
          align: 'left',
          field: 'deliverNum',
          minWidth: 80,
        },
        ,{
          title: '欠货量',
          align: 'left',
          field: 'deliverMissNum',
          minWidth: 80,
        }
      ],
      url: {
        list: window._CONFIG['domianDmsURL'] + '/order/orderReport/findOrderOutStockPageList',
        // detail: window._CONFIG['domianURL'] + '/userorgrelation/cnUserOrgRelation/saveOrUpdate',
        // edit: window._CONFIG['domianURL'] + '/mdsProduct/saveOrUpdateEntity',
        // deleteBatch: '/userorgrelation/cnUserOrgRelation/deleteBatch',
        // delete: window._CONFIG['domianURL'] + '/userorgrelation/cnUserOrgRelation/delete',
        // exportXlsUrl: window._CONFIG['domianTpmURL'] + 'budget/tpmBudgetFee/exportXls'
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.initColumns()
  },
  methods: {
    filterDictText,
    initDictConfig() {
      initDictOptions('line_type').then((res) => {
        if (res.success) {
          this.statusList = res.result
        }
      })
    },
    //列表设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter(item => {
        if (item.key == 'rowIndex' || item.field == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.field)) {
          return true
        }
        return false
      })
      this.columns = cols
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function(item, i, array) {
          allSettingColumns.push(item.field)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.field == 'action') {
            return true
          }
          if (colSettings.includes(item.field)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>
